import fetch from 'common/src/utils/fetch';
import baseUrl from './env';
import UTILS from "common/src/utils/utils";
// 根据竞赛id获取竞赛小类集合
function getSubCompetitions(data) {
  return fetch({
    url: baseUrl + "/sign/competition/getSubCompetitions?id=" + data,
    method: 'get',
    data
  });
}

// 考试竞赛列表查看
function listPage(data) {
  return fetch({
    url: baseUrl + "/sign/competition/listPage",
    method: 'post',
    data
  });
}

// 考试竞赛列表新增
function addCompetition(data) {
  return fetch({
    url: baseUrl + "/sign/competition/addCompetition",
    method: 'post',
    data
  });
}

// 竞赛规则
function getListRole(data) {
  return fetch({
    url: baseUrl + "/sign/Role/getList",
    method: 'post',
    data
  });
}

// 获取竞赛名称下拉
function getCompetitionNames(data) {
  return fetch({
    url: `${baseUrl}/sign/competition/getCompetitionNames?name=${data.name}&year=${data.year}`,
    method: 'get'
  });
}

//  考试竞赛查看
function getDetail(data) {
  return fetch({
    url: baseUrl + "/sign/competition/getDetail?id=" + data,
    method: 'get',
    data
  });
}


// 考试竞赛编辑
function editCompetition(data) {
  return fetch({
    url: baseUrl + "/sign/competition/edit",
    method: 'post',
    data
  });
}

// 考试竞赛导出
function exportList(data) {
  return fetch({
    url: baseUrl + "/sign/competition/exportList",
    method: 'post',
    responseType: 'blob',
    data
  }).then(res => {
    UTILS.downloadFile(res, '考试竞赛.xlsx', 'application/vnd.ms-excel;charset=utf-8');
  });
}


// 学生报名查看
function signUpList(data) {
  return fetch({
    url: baseUrl + "/sign/record/getList",
    method: 'post',
    data
  });
}

// 判断是否可以报名
function getIsEnable(data) {
  return fetch({
    url: baseUrl + "/sign/record/getIsEnable",
    method: 'post',
    data
  });
}

// 模糊搜索教师信息
function getTeacherInfo(data) {
  return fetch({
    url: baseUrl + "/sign/record/getTeacherInfo",
    method: 'post',
    data
  });
}
// 模糊搜索学生信息
function getStudentInfo(data) {
  return fetch({
    url: baseUrl + "/sign/record/getStudentInfo",
    method: 'post',
    data
  });
}

// 报名
function signUp(data) {
  return fetch({
    url: baseUrl + "/sign/record/signUp",
    method: 'post',
    data
  });
}

// 取消报名
function cancelSignUp(data) {
  return fetch({
    url: baseUrl + "/sign/record/cancelSign",
    method: 'post',
    data
  });
}

// 获取当前系统时间
function getCurrentDateStr(key) {
  return fetch({
      url: `${baseUrl}/examCommon/getCurrentDateStr`,
      method: 'get',
      showMask: false
  });
}

// 打印准考证
function printExamCard(data) {
  return fetch({
      url: `${baseUrl}/sign/record/printExamCard`,
      method: 'post',
      responseType:'blob',
      data
  }).then(res => {
      UTILS.downloadFile(res, '准考证.pdf', 'application/pdf;charset=utf-8');
  })
}

export default {
  'listPage': listPage,
  'addCompetition': addCompetition,
  'getListRole': getListRole,
  'getCompetitionNames': getCompetitionNames,
  'getDetail': getDetail,
  'editCompetition': editCompetition,
  'exportList': exportList,
  'signUpList': signUpList,
  'getIsEnable': getIsEnable,
  'getTeacherInfo': getTeacherInfo,
  'getStudentInfo': getStudentInfo,
  'signUp': signUp,
  'cancelSignUp': cancelSignUp,
  'getCurrentDateStr': getCurrentDateStr,
  'printExamCard': printExamCard,
  'getSubCompetitions': getSubCompetitions
};
